package top.huxy.boot.controller.all;

import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import top.huxy.boot.annotation.RequestRemake;
import top.huxy.boot.model.dto.Pager;
import top.huxy.boot.model.vo.VOBlog;
import top.huxy.boot.model.vo.VOBlogQuery;
import top.huxy.boot.service.impl.BlogServiceImpl;
import top.huxy.boot.util.obj.Result;

import java.util.List;

/**
 * @Classname BlogController
 * @Description Blog控制器
 * @Date 2021/8/30 19:06
 * @Created by huxy
 */
//@RestController
//@RequestMapping("/blog")
//@ListeningExcutionTime
public class BlogController {

    BlogServiceImpl blogService;

    public BlogController(BlogServiceImpl blogService) {
        this.blogService = blogService;
    }

    @GetMapping("/getBlogList")
    @RequestRemake("查看博客列表")
    public Result getBlogList(Pager pager) {
        //查询数据
        List<VOBlog> blogList = blogService.getBlogList(pager);

        //封装数据
        PageInfo<VOBlog> blogPageInfo = new PageInfo<>(blogList);

        return Result.success(blogPageInfo);
    }

    @GetMapping("/getBlogById")
    @RequestRemake("查看博客")
    public Result getBlogById(@RequestParam("id") Integer id) {
        VOBlog content = blogService.getBlogById(id);
        return Result.success(content);
    }

    @GetMapping("/selectBlogByTitle")
    @RequestRemake("搜索博客")
    public Result selectBlogByTitle(@RequestParam("query") String query) {
        List<VOBlogQuery> list = blogService.selectBlogByTitle(query);
        return Result.success(list);
    }
}
